package com.my.interview.lock;

import java.util.concurrent.locks.ReentrantLock;

public class ReentrantLockFairLock {

    //ReentrantLock 公平锁
    private ReentrantLock lock = new ReentrantLock(true);


    public void lock(){
        lock.lock();
    }

    public void run() {

        try{
            System.out.println(Thread.currentThread().getName() + " 锁定");
            long start = System.currentTimeMillis();
            //Thread.sleep(30);
            System.out.println("end======" + (System.currentTimeMillis() - start));
        }catch (Exception e){


        }finally {

        }


    }

    public void unlock(){
        lock.unlock();
    }
}
